package itheima.com.socketdemo8;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(6666);

        Socket accept = ss.accept();
        //网络中的流 用来将数据从客户端读取出来
        BufferedInputStream bis = new BufferedInputStream(accept.getInputStream());
        //本地的IO流 用来将数据存储到本地
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("Day15\\Server\\copy.jpg"));

        int b;
        while ((b=bis.read())!=-1){
            bos.write(b);
        }

        BufferedWriter fw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        fw.write("文件传送完毕");
        fw.newLine();
        fw.flush();

        bos.close();
        accept.close();
        ss.close();
    }
}
